package com.shanwen.select.task;


import com.shanwen.select.entity.WeixinUserInfo;
import com.shanwen.select.service.WeixinUserInfoSerivice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class DailyTask {
    @Autowired
    WeixinUserInfoSerivice userInfoSerivice;

    @Scheduled(cron = "0 0 0 * * ? ")
    public void push() {
        List<WeixinUserInfo> userInfos = userInfoSerivice.list();
        Date date = new Date();
        userInfos.forEach(userInfo -> {
            if (userInfo.getExpireDate().getTime() > date.getTime()) {
                userInfo.setLevel(0);
                userInfoSerivice.updateById(userInfo);
            }
        });
    }
}

